In [1]:
import pandas as pd
import pandas_datareader as web
import numpy as np
import pytrends

We want:

  • stock prices for several companies from various sectors, daily data over many years
  • main index, daily data over many years
  • sector information for every one of those companies
  • google domestic trends data hardest to get - either all, or the most important, of indicators, daily, for the entire period. Query 4 months at a time to obtain daily data (otherwise it's monthly - according to pytrends documentation)

make a google account for the purpose of getting google d trends.


In [2]:
from pytrends.request import TrendReq

In [12]:
google_username = "mm.trends.api@gmail.com"
google_password = ""
path = ""

In [8]:
# connect to Google
pytrend = TrendReq(google_username, google_password, custom_useragent='Pytrends')

In [5]:
trend_payload = {'q': 'Pizza, Italian, Spaghetti, Breadsticks, Sausage', 'cat': '0-71'}

In [ ]:
# trend
trend = pytrend.trend(trend_payload)
print(trend)
df = pytrend.trend(trend_payload, return_type='dataframe')

In [7]:
df


Out[7]:
breadsticks italian pizza sausage spaghetti
Date
2004-01-01 0.0 9.0 33.0 3.0 3.0
2004-02-01 0.0 10.0 32.0 2.0 3.0
2004-03-01 0.0 9.0 31.0 2.0 3.0
2004-04-01 0.0 9.0 33.0 2.0 2.0
2004-05-01 0.0 9.0 32.0 2.0 2.0
2004-06-01 0.0 8.0 30.0 2.0 2.0
2004-07-01 0.0 8.0 33.0 2.0 3.0
2004-08-01 0.0 8.0 33.0 2.0 3.0
2004-09-01 0.0 9.0 32.0 2.0 3.0
2004-10-01 0.0 10.0 36.0 2.0 3.0
2004-11-01 0.0 11.0 33.0 4.0 3.0
2004-12-01 0.0 11.0 35.0 4.0 3.0
2005-01-01 0.0 9.0 38.0 3.0 3.0
2005-02-01 0.0 10.0 39.0 3.0 3.0
2005-03-01 0.0 10.0 38.0 2.0 3.0
2005-04-01 0.0 9.0 38.0 2.0 3.0
2005-05-01 0.0 9.0 37.0 2.0 3.0
2005-06-01 0.0 8.0 35.0 2.0 2.0
2005-07-01 0.0 8.0 39.0 2.0 3.0
2005-08-01 0.0 8.0 39.0 2.0 3.0
2005-09-01 0.0 9.0 39.0 2.0 4.0
2005-10-01 0.0 9.0 39.0 3.0 4.0
2005-11-01 0.0 10.0 40.0 4.0 3.0
2005-12-01 0.0 11.0 43.0 4.0 3.0
2006-01-01 0.0 9.0 42.0 3.0 4.0
2006-02-01 0.0 10.0 44.0 3.0 3.0
2006-03-01 0.0 9.0 42.0 2.0 3.0
2006-04-01 0.0 9.0 43.0 2.0 3.0
2006-05-01 0.0 9.0 40.0 2.0 3.0
2006-06-01 0.0 8.0 41.0 2.0 3.0
... ... ... ... ... ...
2014-05-01 0.0 8.0 78.0 4.0 6.0
2014-06-01 0.0 8.0 78.0 4.0 6.0
2014-07-01 0.0 8.0 81.0 4.0 6.0
2014-08-01 0.0 9.0 83.0 4.0 7.0
2014-09-01 0.0 8.0 75.0 4.0 7.0
2014-10-01 0.0 8.0 79.0 5.0 8.0
2014-11-01 0.0 8.0 82.0 6.0 7.0
2014-12-01 0.0 9.0 85.0 6.0 6.0
2015-01-01 0.0 8.0 84.0 5.0 7.0
2015-02-01 0.0 8.0 85.0 5.0 7.0
2015-03-01 0.0 8.0 80.0 5.0 6.0
2015-04-01 0.0 8.0 81.0 5.0 6.0
2015-05-01 0.0 8.0 85.0 5.0 6.0
2015-06-01 0.0 8.0 86.0 5.0 6.0
2015-07-01 0.0 9.0 89.0 4.0 6.0
2015-08-01 0.0 9.0 87.0 5.0 7.0
2015-09-01 0.0 8.0 84.0 5.0 8.0
2015-10-01 0.0 9.0 88.0 6.0 8.0
2015-11-01 0.0 9.0 85.0 6.0 7.0
2015-12-01 0.0 10.0 92.0 7.0 7.0
2016-01-01 0.0 9.0 93.0 6.0 8.0
2016-02-01 0.0 9.0 94.0 5.0 7.0
2016-03-01 0.0 9.0 90.0 6.0 7.0
2016-04-01 0.0 9.0 91.0 5.0 7.0
2016-05-01 0.0 9.0 90.0 5.0 6.0
2016-06-01 0.0 9.0 94.0 5.0 7.0
2016-07-01 0.0 9.0 100.0 6.0 7.0
2016-08-01 0.0 9.0 91.0 11.0 7.0
2016-09-01 0.0 9.0 89.0 7.0 8.0
2016-10-01 0.0 9.0 90.0 7.0 9.0

154 rows × 5 columns


In [ ]:
# toprelated
toprelated = pytrend.related(trend_payload, related_type='top')
print(toprelated)
risingrelated = pytrend.related(trend_payload, related_type='rising')
print(risingrelated)

# top30in30
top30in30 = pytrend.top30in30()
print(top30in30)

country_payload = {'geo': 'US'}
# hottrends
hottrends = pytrend.hottrends(country_payload)
print(hottrends)

# hottrendsdetail
# returns XML data
hottrendsdetail = pytrend.hottrendsdetail(country_payload)
print(hottrendsdetail)

payload = {'date': '201601', 'geo': 'US'}
# alltopcharts
topcharts = pytrend.topcharts(payload)
print(topcharts)

keyword = 'pizza'
# suggestions
suggestions = pytrend.suggestions(keyword)
print(suggestions)
  • GOOGLEINDEX_US:ADVERT This Google Advertising & Marketing Index tracks searches related to (marketing, advertising, commercials...)

  • GOOGLEINDEX_US:AIRTVL This Google Air Travel Index tracks searches related to (airlines, airline, flights...)

  • GOOGLEINDEX_US:AUTOBY This Google Auto Buyers Index tracks searches related to (car, blue book...)

  • GOOGLEINDEX_US:AUTOFI This Google Auto Financing Index tracks searches related to (loan, car lean...)

  • GOOGLEINDEX_US:AUTO This Google Automotive Index tracks searches related to (car, honda, toyota...)

  • GOOGLEINDEX_US:PERFIN This Google Personal Finance Index tracks searches related to (bank, bank of america...)

  • GOOGLEINDEX_US:BIZ This Google Business Index tracks searches related to (calendar, business, salary...)

  • GOOGLEINDEX_US:COMPUT This Google Computers & Electronics Index tracks searches related to (windows, download, microsoft...)

  • GOOGLEINDEX_US:CONSTR This Google Construction Index tracks searches related to (doors, construction...)

  • GOOGLEINDEX_US:CREDIT This Google Credit & Lending Index tracks searches related to (credit, credit card, loans...)

  • GOOGLEINDEX_US:DURBLE This Google Durable Goods Index tracks searches related to (vacuum, appliances, refrigerator...)

  • GOOGLEINDEX_US:FININS This Google Finance & Insurance Index tracks searches related to (stock, bank, yahoo...)

  • GOOGLEINDEX_US:FURNTR This Google Furniture Index tracks searches related to (ikea, furniture, table...)

  • GOOGLEINDEX_US:INDUST This Google Industries Index tracks searches related to (home, energy, usps...)

  • GOOGLEINDEX_US:INVEST This Google Investing Index tracks searches related to (finance, stocks, capital, stock...)

  • GOOGLEINDEX_US:JOBS This Google Jobs Index tracks searches related to (city, jobs, resume, monster...)

  • GOOGLEINDEX_US:LUXURY This Google Luxuries Index tracks searches related to (diamond, jewelers, rings, tiffany...)

  • GOOGLEINDEX_US:MTGE This Google Mortgage Index tracks searches related to (mortgage calculator, mortage rates, mortgage...)

  • GOOGLEINDEX_US:RLEST This Google Real Estate Index tracks searches related to (mortgage,apartmenents, real estate, rent...)

  • GOOGLEINDEX_US:RENTAL This Google Rental Index tracks searches related to (for rent, rent, rentals...)

  • GOOGLEINDEX_US:RETAIL This Google Retail Index tracks searches related to (bags, vending, retail...)

  • GOOGLEINDEX_US:TRAVEL This Google Travel Index tracks searches related to (hotel, vegas, airlines...)

  • GOOGLEINDEX_US:UNEMPL This Google Unemployment Index tracks searches related to (social security, unemployment...)


In [12]:
gt = pd.read_table?

In [ ]:
gt = pd.read_clipboard(index_col)

In [9]:
gt


Out[9]:
Date GOOGLEINDEX_US:ADVERT GOOGLEINDEX_US:AIRTVL GOOGLEINDEX_US:AUTO GOOGLEINDEX_US:AUTOBY GOOGLEINDEX_US:AUTOFI GOOGLEINDEX_US:BIZIND GOOGLEINDEX_US:BNKRPT GOOGLEINDEX_US:COMLND GOOGLEINDEX_US:COMPUT ... GOOGLEINDEX_US:JOBS GOOGLEINDEX_US:LUXURY GOOGLEINDEX_US:MOBILE GOOGLEINDEX_US:MTGE GOOGLEINDEX_US:RENTAL GOOGLEINDEX_US:RLEST GOOGLEINDEX_US:SHOP GOOGLEINDEX_US:SMALLBIZ GOOGLEINDEX_US:TRAVEL GOOGLEINDEX_US:UNEMPL
0 2004-01-01 1.00 1.00 1.00 1.00 NaN 1.00 NaN NaN 1.00 ... 1.00 NaN 1.00 1.00 1.00 1.00 1.00 1.00 1.00 1.00
1 2004-01-02 1.00 1.00 1.02 1.04 1.00 1.09 NaN NaN 0.99 ... 1.17 1.00 1.01 1.00 1.00 1.02 0.95 1.00 0.98 1.00
2 2004-01-03 1.06 0.99 1.02 1.07 0.91 1.06 NaN NaN 0.98 ... 1.17 0.95 1.00 0.89 0.96 1.01 0.94 1.02 0.95 1.02
3 2004-01-04 1.12 1.01 1.01 1.07 0.88 1.06 NaN NaN 0.97 ... 1.22 0.99 0.99 0.86 0.96 1.01 0.94 1.04 0.95 1.03
4 2004-01-05 1.18 1.02 1.02 1.05 0.87 1.06 NaN NaN 0.97 ... 1.29 NaN 1.00 0.88 0.96 0.99 0.93 1.06 0.94 1.05
5 2004-01-06 1.24 1.03 1.00 1.04 0.86 1.15 NaN NaN 0.96 ... 1.37 1.00 0.99 0.91 0.97 0.99 0.90 1.08 0.96 1.00
6 2004-01-07 1.25 1.04 0.99 1.02 1.00 1.19 1.00 NaN 0.96 ... 1.43 1.00 0.99 0.93 0.97 0.98 0.88 1.09 0.96 1.00
7 2004-01-08 1.27 1.05 0.98 1.00 1.00 1.25 0.95 NaN 0.95 ... 1.53 1.02 0.98 0.95 0.96 0.97 0.85 1.09 0.96 1.00
8 2004-01-09 1.31 1.05 0.96 0.97 1.00 1.28 0.94 NaN 0.95 ... 1.57 1.03 0.98 0.94 0.95 0.96 0.83 1.10 0.97 1.00
9 2004-01-10 1.31 1.05 0.96 0.96 1.01 1.29 0.93 NaN 0.95 ... 1.58 1.05 0.98 0.95 0.95 0.96 0.82 1.10 0.98 1.00
10 2004-01-11 1.29 1.04 0.96 0.96 1.01 1.29 0.93 NaN 0.95 ... 1.57 1.07 0.98 0.94 0.95 0.95 0.82 1.10 0.98 1.00
11 2004-01-12 1.30 1.03 0.94 0.96 1.00 1.34 0.92 NaN 0.94 ... 1.61 1.00 0.97 0.97 0.95 0.96 0.80 1.09 0.99 1.00
12 2004-01-13 1.30 1.02 0.94 0.96 1.02 1.32 1.00 NaN 0.95 ... 1.60 1.07 0.96 0.98 0.96 0.95 0.80 1.08 0.99 1.12
13 2004-01-14 1.33 1.00 0.94 0.97 1.03 1.32 0.91 NaN 0.95 ... 1.59 1.07 0.95 0.99 0.95 0.95 0.79 1.09 0.99 1.10
14 2004-01-15 1.33 0.99 0.94 0.97 1.03 1.33 0.91 NaN 0.94 ... 1.59 1.11 0.94 1.01 0.95 0.95 0.79 1.09 0.99 0.98
15 2004-01-16 1.33 0.98 0.94 0.98 1.05 1.33 0.91 NaN 0.94 ... 1.58 1.11 0.94 1.02 0.94 0.94 0.79 1.08 0.99 0.97
16 2004-01-17 1.35 0.98 0.95 0.99 1.07 1.32 0.92 NaN 0.94 ... 1.57 1.11 0.94 1.03 0.95 0.95 0.78 1.09 0.99 0.96
17 2004-01-18 1.36 0.98 0.95 1.00 1.08 1.32 0.94 NaN 0.94 ... 1.56 1.10 0.93 1.03 0.94 0.95 0.78 1.07 0.99 0.94
18 2004-01-19 1.32 0.97 0.95 1.00 1.10 1.31 0.96 NaN 0.95 ... 1.53 1.09 0.93 1.02 0.94 0.95 0.79 1.06 0.99 0.92
19 2004-01-20 1.33 0.97 0.95 0.99 1.00 1.31 1.00 NaN 0.95 ... 1.52 1.02 0.93 1.02 0.94 0.96 0.79 1.05 0.98 1.02
20 2004-01-21 1.31 0.97 0.95 1.00 1.00 1.30 0.93 NaN 0.94 ... 1.53 1.00 0.93 1.03 0.94 0.96 0.79 1.05 0.97 0.97
21 2004-01-22 1.32 0.95 0.95 0.99 0.98 1.30 0.94 NaN 0.94 ... 1.52 0.98 0.92 1.03 0.94 0.96 0.78 1.04 0.97 0.96
22 2004-01-23 1.33 0.95 0.94 1.00 0.97 1.30 0.86 NaN 0.94 ... 1.51 0.89 0.91 1.04 0.93 0.96 0.78 1.05 0.96 0.95
23 2004-01-24 1.31 0.94 0.94 1.00 0.96 1.31 0.86 NaN 0.94 ... 1.51 0.89 0.91 1.05 0.93 0.96 0.78 1.05 0.95 0.95
24 2004-01-25 1.29 0.93 0.94 1.00 0.94 1.32 0.86 NaN 0.94 ... 1.52 0.89 0.91 1.07 0.94 0.96 0.78 1.06 0.95 0.95
25 2004-01-26 1.32 0.94 0.93 1.00 1.07 1.34 0.86 NaN 0.93 ... 1.52 0.89 0.89 1.10 0.93 0.96 0.77 1.07 0.95 0.92
26 2004-01-27 1.33 0.95 0.93 1.00 1.07 1.35 1.00 NaN 0.93 ... 1.51 0.89 0.89 1.09 0.91 0.95 0.77 1.08 0.95 1.00
27 2004-01-28 1.35 0.96 0.93 1.00 1.02 1.35 0.93 NaN 0.94 ... 1.50 0.97 0.88 1.08 0.91 0.95 0.77 1.07 0.95 1.00
28 2004-01-29 1.38 0.97 0.93 1.00 1.00 1.35 1.00 NaN 0.94 ... 1.50 0.97 0.88 1.08 0.92 0.95 0.77 1.06 0.95 0.99
29 2004-01-30 1.39 0.96 0.93 0.99 1.06 1.35 0.95 NaN 0.94 ... 1.50 0.97 0.87 1.07 0.93 0.95 0.77 1.04 0.94 0.99
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
4634 2016-09-08 0.69 0.72 0.88 0.70 0.79 1.10 0.44 0.68 0.44 ... 1.26 0.57 1.22 0.73 1.24 0.86 0.81 0.70 0.75 0.69
4635 2016-09-09 0.70 0.71 0.88 0.70 0.79 1.10 0.45 0.68 0.44 ... 1.28 0.57 1.29 0.75 1.22 0.86 0.81 0.70 0.74 0.69
4636 2016-09-10 0.71 0.71 0.88 0.70 0.79 1.10 0.46 0.68 0.44 ... 1.29 0.56 1.33 0.75 1.22 0.85 0.81 0.70 0.73 0.69
4637 2016-09-11 0.71 0.71 0.87 0.69 0.78 1.10 0.45 0.68 0.45 ... 1.29 0.55 1.35 0.74 1.20 0.84 0.80 0.69 0.71 0.69
4638 2016-09-12 0.75 0.71 0.86 0.68 0.80 1.13 0.48 0.68 0.46 ... 1.36 0.55 1.35 0.78 1.20 0.84 0.77 0.71 0.70 0.73
4639 2016-09-13 0.76 0.70 0.85 0.68 0.79 1.12 0.47 0.69 0.46 ... 1.36 0.54 1.35 0.77 1.19 0.83 0.76 0.71 0.70 0.71
4640 2016-09-14 0.76 0.70 0.84 0.67 0.79 1.12 0.47 0.68 0.45 ... 1.36 0.53 1.23 0.77 1.17 0.82 0.76 0.71 0.70 0.69
4641 2016-09-15 0.75 0.70 0.84 0.67 0.80 1.12 0.47 0.67 0.45 ... 1.37 0.53 1.12 0.77 1.16 0.82 0.76 0.71 0.69 0.69
4642 2016-09-16 0.75 0.70 0.84 0.67 0.79 1.12 0.46 0.67 0.45 ... 1.37 0.53 1.08 0.76 1.16 0.81 0.76 0.72 0.70 0.68
4643 2016-09-17 0.75 0.70 0.84 0.68 0.80 1.12 0.46 0.66 0.45 ... 1.37 0.53 1.08 0.75 1.16 0.81 0.76 0.72 0.70 0.68
4644 2016-09-18 0.75 0.70 0.84 0.68 0.80 1.12 0.46 0.66 0.45 ... 1.37 0.53 1.08 0.75 1.18 0.81 0.76 0.72 0.69 0.68
4645 2016-09-19 0.75 0.70 0.84 0.68 0.80 1.13 0.46 0.65 0.45 ... 1.38 0.52 1.09 0.75 1.17 0.81 0.76 0.72 0.69 0.68
4646 2016-09-20 0.75 0.69 0.83 0.69 0.80 1.14 0.46 0.66 0.45 ... 1.38 0.53 1.09 0.74 1.17 0.81 0.76 0.73 0.69 0.67
4647 2016-09-21 0.75 0.69 0.83 0.68 0.79 1.13 0.46 0.66 0.45 ... 1.37 0.53 1.09 0.74 1.17 0.81 0.76 0.72 0.68 0.67
4648 2016-09-22 0.75 0.69 0.83 0.68 0.79 1.13 0.45 0.66 0.45 ... 1.36 0.53 1.08 0.72 1.16 0.81 0.76 0.72 0.68 0.67
4649 2016-09-23 0.74 0.69 0.83 0.68 0.79 1.13 0.45 0.66 0.45 ... 1.36 0.52 1.05 0.71 1.16 0.81 0.76 0.72 0.68 0.67
4650 2016-09-24 0.74 0.69 0.83 0.68 0.78 1.13 0.44 0.66 0.45 ... 1.36 0.52 1.02 0.70 1.14 0.81 0.76 0.72 0.67 0.67
4651 2016-09-25 0.75 0.68 0.83 0.67 0.78 1.12 0.45 0.67 0.45 ... 1.36 0.52 1.01 0.70 1.12 0.81 0.76 0.73 0.68 0.66
4652 2016-09-26 0.75 0.68 0.83 0.67 0.78 1.11 0.44 0.67 0.45 ... 1.35 0.52 0.99 0.70 1.12 0.80 0.76 0.73 0.68 0.66
4653 2016-09-27 0.74 0.68 0.83 0.66 0.77 1.11 0.46 0.67 0.45 ... 1.34 0.52 0.97 0.69 1.11 0.80 0.76 0.73 0.67 0.65
4654 2016-09-28 0.74 0.67 0.83 0.66 0.77 1.11 0.47 0.68 0.45 ... 1.34 0.52 0.96 0.69 1.11 0.80 0.76 0.73 0.67 0.65
4655 2016-09-29 0.74 0.68 0.83 0.66 0.77 1.11 0.47 0.67 0.45 ... 1.35 0.54 0.96 0.69 1.12 0.79 0.76 0.74 0.67 0.65
4656 2016-09-30 0.75 0.67 0.82 0.66 0.77 1.11 0.47 0.68 0.45 ... 1.34 0.54 0.95 0.71 1.12 0.79 0.77 0.74 0.67 0.65
4657 2016-10-01 0.75 0.67 0.82 0.66 0.77 1.11 0.48 0.69 0.45 ... 1.34 0.54 0.95 0.72 1.13 0.79 0.77 0.74 0.67 0.66
4658 2016-10-02 0.75 0.67 0.81 0.66 0.77 1.11 0.47 0.70 0.45 ... 1.33 0.54 0.94 0.73 1.14 0.79 0.77 0.74 0.67 0.66
4659 2016-10-03 0.75 0.67 0.81 0.65 0.77 1.11 0.48 0.72 0.44 ... 1.32 0.54 0.94 0.74 1.15 0.79 0.78 0.74 0.67 0.67
4660 2016-10-04 0.75 0.68 0.81 0.66 0.78 1.11 0.46 0.72 0.44 ... 1.31 0.54 0.95 0.74 1.15 0.79 0.78 0.74 0.67 0.68
4661 2016-10-05 0.74 0.69 0.81 0.65 0.78 1.11 0.45 0.73 0.44 ... 1.30 0.53 0.95 0.74 1.15 0.79 0.78 0.73 0.67 0.68
4662 2016-10-06 0.74 0.70 0.80 0.65 0.77 1.10 0.44 0.74 0.44 ... 1.29 0.51 0.95 0.73 1.14 0.80 0.78 0.72 0.68 0.69
4663 2016-10-07 0.74 0.71 0.80 0.65 0.76 1.10 0.44 0.73 0.44 ... 1.28 0.50 0.94 0.72 1.13 0.81 0.78 0.71 0.68 0.68

4664 rows × 28 columns


In [ ]:


In [ ]: